package com.yxq.mdt.app.modules.socialcontact.ui.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.yxq.mdt.app.R;
import com.yxq.mdt.app.base.BaseFragment;
import com.yxq.mdt.app.modules.socialcontact.adapter.HomeLoveAdapter;
import com.yxq.mdt.app.modules.socialcontact.adapter.HomeSeedingAdapter;
import com.yxq.mdt.app.modules.socialcontact.adapter.HomeTypeAdapter;
import com.yxq.mdt.app.modules.socialcontact.adapter.HomeUserProAdapter;
import com.yxq.mdt.app.modules.socialcontact.bean.GivePresentBean;
import com.yxq.mdt.app.modules.socialcontact.bean.SocialPersonalHomepageBean;
import com.yxq.mdt.app.modules.socialcontact.bean.SocialPersonalMyHomepageBean;
import com.yxq.mdt.app.modules.socialcontact.model.MainSocialContactModel;
import com.yxq.mdt.app.modules.socialcontact.presenter.MainSocialPersonalHomePresenter;
import com.yxq.mdt.app.modules.socialcontact.presenter.mainSocialPersonalHomeContract;
import com.yxq.mdt.app.modules.socialcontact.ui.activity.VideoInviteChatActivity;
import com.yxq.mdt.app.modules.socialcontact.ui.activity.VoiceInviteChatActivity;
import com.yxq.mdt.app.utils.RatingBar;
import com.yxq.mdt.app.utils.StringUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * 资料
 */
public class SocialMaterialFragment extends BaseFragment<MainSocialPersonalHomePresenter> implements mainSocialPersonalHomeContract.View {
    public static final String EXTRA_TEXT = "extra_text";
    @BindView(R.id.ratingBar)
    RatingBar ratingBar;
    @BindView(R.id.social_come_day)
    TextView socialComeDay;
    @BindView(R.id.social_come_number)
    TextView socialComeNumber;
    @BindView(R.id.social_come_year)
    TextView socialComeYear;
    @BindView(R.id.social_come_constellation)
    TextView socialComeConstellation;
    @BindView(R.id.social_come_Single)
    TextView socialComeSingle;
    @BindView(R.id.social_come_orientation)
    TextView socialComeOrientation;
    @BindView(R.id.social_come_accompanying)
    TextView socialComeAccompanying;
    @BindView(R.id.social_come_location)
    TextView socialComeLocation;
    @BindView(R.id.social_come_hometown)
    TextView socialComeHometown;
    @BindView(R.id.label_recycler)
    RecyclerView labelRecycler;
    @BindView(R.id.type_recycler)
    RecyclerView typeRecycler;
    @BindView(R.id.evaluate_recycler)
    RecyclerView evaluateRecycler;
    @BindView(R.id.label_recycler_lint)
    LinearLayout labelRecyclerLint;
    @BindView(R.id.type_recycler_lint)
    LinearLayout typeRecyclerLint;
    @BindView(R.id.evaluate_recycler_lint)
    LinearLayout evaluateRecyclerLint;
    @BindView(R.id.social_come_img)
    ImageView socialComeImg;
    @BindView(R.id.social_come_rate)
    TextView socialComeRate;
    @BindView(R.id.social_come_chat_lint)
    LinearLayout socialComeChatLint;
    @BindView(R.id.social_come_hometown_lint)
    LinearLayout socialComeHometownLint;
    @BindView(R.id.social_no_year)
    TextView socialNoYear;
    @BindView(R.id.social_no_orientation)
    LinearLayout socialNoOrientation;
    @BindView(R.id.social_no_single)
    LinearLayout socialNoSingle;
    @BindView(R.id.social_no_location)
    LinearLayout socialNoLocation;
    @BindView(R.id.social_no_accompanying)
    LinearLayout socialNoAccompanying;
    @BindView(R.id.social_no_hometown)
    LinearLayout socialNoHometown;
    @BindView(R.id.label_lint_text)
    TextView labelLintText;
    @BindView(R.id.type_lint_text)
    TextView typeLintText;
    @BindView(R.id.evaluate_lint_text)
    TextView evaluateLintText;
    @BindView(R.id.social_no_constellation)
    LinearLayout socialNoConstellation;
    @BindView(R.id.social_come_num)
    TextView socialComeNum;
    @BindView(R.id.seeding_evaluation_recycler)
    RecyclerView seedingEvaluationRecycler;
    @BindView(R.id.my_chat)
    TextView myChat;
    @BindView(R.id.social_come_money)
    TextView socialComeMoney;
    private List<GivePresentBean.DataBean.ListBean> givePresentBeans;
    String name, userId;
    HomeTypeAdapter homeTypeAdapter;
    HomeLoveAdapter homeLoveAdapter;
    HomeUserProAdapter homeUserProAdapter;
    HomeSeedingAdapter homeSeedingAdapter;

    @Override
    protected int attachLayoutId() {
        setImmersionBarEnabled(false);
        return R.layout.fragment_social_material;
    }

    @Override
    protected MainSocialPersonalHomePresenter getPresenter() {
        return new MainSocialPersonalHomePresenter(this, new MainSocialContactModel());
    }


    @Override
    public void initView(View view) {
        givePresentBeans = new ArrayList<>();
        ratingBar.setClickable(false);//设置可否点击
        ratingBar.setStar(2.5f);//设置显示的星星个数
        ratingBar.setStepSize(RatingBar.StepSize.Full);//设置每次点击增加一颗星还是半颗星
        ratingBar.setOnRatingChangeListener(ratingCount -> {//点击星星变化后选中的个数

        });
        Bundle bundle = getArguments();
        if (bundle != null) {
            userId = bundle.getString("userId");
        }

    }


    @Override
    public void initData() {
        mPresenter.getGaUserExtVoById(userId);
        mPresenter.getSelectByGsPresentPageList();
    }

    @Override
    public void setData(@Nullable Object data) {

    }


    @Override
    public void onLoadMyGaUserExtVoByIdSuccess(SocialPersonalMyHomepageBean socialPersonalMyHomepageBean) {

    }

    @Override
    public void onLoadMyGaUserExtVoByIdFailed() {

    }

    @Override
    public void onLoadGaUserExtVoByIdSuccess(SocialPersonalHomepageBean socialPersonalHomepageBean) {
        if (socialPersonalHomepageBean.getSoundsVideoStatus() == 0) {
            socialComeChatLint.setVisibility(View.GONE);
        } else {
            socialComeChatLint.setVisibility(View.VISIBLE);
        }
        socialComeNum.setText(socialPersonalHomepageBean.getCommentIntegralNum() + "分");
        float f = socialPersonalHomepageBean.getCommentIntegralNum();
        ratingBar.setStar(f);//设置显示的星星个数
        name = socialPersonalHomepageBean.getGsName();
        socialComeDay.setText(socialPersonalHomepageBean.getDays() + "天");
        socialComeNumber.setText(socialPersonalHomepageBean.getId() + "");

        if (socialPersonalHomepageBean.getBirthdayShow() != 1) {
            socialComeYear.setText(String.valueOf(socialPersonalHomepageBean.getAge()) + "");
            String[] bir = socialPersonalHomepageBean.getBirthday().split("-");
            socialComeConstellation.setText(StringUtils.getConstellation(Integer.parseInt(bir[1]), Integer.parseInt(bir[2])));
        } else {
            socialComeYear.setText("保密");
            socialComeConstellation.setText("保密");
        }
        if (socialPersonalHomepageBean.getMarriageShow() != 1) {
            socialComeSingle.setText(socialPersonalHomepageBean.getMarriage());
        } else {
            socialComeSingle.setText("保密");
        }
        if (socialPersonalHomepageBean.getSexualShow() != 1) {
            socialComeOrientation.setText(socialPersonalHomepageBean.getSexual());
        } else {
            socialComeOrientation.setText("保密");
        }

        socialComeAccompanying.setText(socialPersonalHomepageBean.getFriendsIntention());
        if (socialPersonalHomepageBean.getResidence() != null) {
            socialComeLocation.setText(socialPersonalHomepageBean.getResidence());
        }
        if (socialPersonalHomepageBean.getHometown() != null || !socialPersonalHomepageBean.getHometown().equals("")) {
            socialComeHometown.setText(socialPersonalHomepageBean.getHometown());
        }
        socialComeRate.setText("接通率" + socialPersonalHomepageBean.getConnectionRate());
        if (socialPersonalHomepageBean.getSoundsVideoStatus() == 0) {
            socialComeChatLint.setVisibility(View.GONE);
        } else {
            socialComeChatLint.setVisibility(View.VISIBLE);
            if (socialPersonalHomepageBean.isCurrentUserStatus()) {
                myChat.setText("我的蜜聊");
            } else {
                myChat.setText("Ta的蜜聊");
            }
        }
        socialComeMoney.setText(socialPersonalHomepageBean.getVoicePrice() + "/蜜豆/分钟");
        switch (socialPersonalHomepageBean.getSoundsVideoStatus()) {
            case 1:
                socialComeImg.setImageResource(R.mipmap.icon_community_users_telephone);
                break;
            case 2:
                socialComeImg.setImageResource(R.mipmap.icon_community_users_video_new);
                break;
        }
        socialComeImg.setOnClickListener(view -> {
            String YXQUserId = "yxq" + userId;
            if (socialPersonalHomepageBean.getSoundsVideoStatus() == 1) {
                //语音
                Intent goToChat = new Intent(mContext, VoiceInviteChatActivity.class);
                goToChat.putExtra("userId", YXQUserId);
                goToChat.putExtra("nickname", name);
                startActivity(goToChat);
            } else if (socialPersonalHomepageBean.getSoundsVideoStatus() == 2) {
                //视频
                Intent goToChat = new Intent(mContext, VideoInviteChatActivity.class);
                goToChat.putExtra("userId", YXQUserId);
                goToChat.putExtra("nickname", name);
                startActivity(goToChat);
            }
        });
        //直播评价
        if (socialPersonalHomepageBean.getCommentContentList() == null) {
            seedingEvaluationRecycler.setVisibility(View.GONE);
        } else {
            seedingEvaluationRecycler.setVisibility(View.VISIBLE);
            homeSeedingAdapter = new HomeSeedingAdapter(R.layout.item_type_seeding_btn, socialPersonalHomepageBean.getCommentContentList());
            seedingEvaluationRecycler.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false));
            seedingEvaluationRecycler.setAdapter(homeSeedingAdapter);
        }
        //个性标签
        if (socialPersonalHomepageBean.getUserProfile() == null || "".equals(socialPersonalHomepageBean.getUserProfile())) {
            // labelRecyclerLint.setVisibility(View.GONE);
        } else {
            String[] Interest = socialPersonalHomepageBean.getUserProfile().split(",");
            List<String> listInterest = new ArrayList<>();
            for (int i = 0; i < Interest.length; i++) {
                listInterest.add(Interest[i]);
            }
            if (listInterest != null && listInterest.size() != 0) {
                labelRecyclerLint.setVisibility(View.VISIBLE);
                homeTypeAdapter = new HomeTypeAdapter(R.layout.item_type_text_btn, listInterest);
                labelRecycler.setLayoutManager(new GridLayoutManager(mContext, 4));
                labelRecycler.setAdapter(homeTypeAdapter);
            } else {
                //  labelRecyclerLint.setVisibility(View.GONE);
            }

        }
        //喜欢类型
        if (socialPersonalHomepageBean.getLoveType() == null || "".equals(socialPersonalHomepageBean.getLoveType())) {
            //typeRecyclerLint.setVisibility(View.GONE);
        } else {
            String[] LoveTypeArr = socialPersonalHomepageBean.getLoveType().split(",");
            List<String> LoveTypeLst = new ArrayList<>();
            for (int i = 0; i < LoveTypeArr.length; i++) {
                LoveTypeLst.add(LoveTypeArr[i]);
            }
            if (LoveTypeLst != null && LoveTypeLst.size() != 0) {
                typeRecyclerLint.setVisibility(View.VISIBLE);
                homeUserProAdapter = new HomeUserProAdapter(R.layout.item_type_text_btn, LoveTypeLst);
                typeRecycler.setLayoutManager(new GridLayoutManager(mContext, 4));
                typeRecycler.setAdapter(homeUserProAdapter);
            } else {
                //typeRecyclerLint.setVisibility(View.GONE);
            }

        }
        //好友评价
        if (socialPersonalHomepageBean.getInterest() == null || "".equals(socialPersonalHomepageBean.getInterest())) {
            // evaluateRecyclerLint.setVisibility(View.GONE);
        } else {
            String[] UserProfile = socialPersonalHomepageBean.getInterest().split(",");
            List<String> UserProfileList = new ArrayList<>();
            for (int i = 0; i < UserProfile.length; i++) {
                UserProfileList.add(UserProfile[i]);
            }
            if (UserProfileList != null && UserProfileList.size() != 0) {
                evaluateRecyclerLint.setVisibility(View.VISIBLE);
                homeLoveAdapter = new HomeLoveAdapter(R.layout.item_type_text_evaluate, UserProfileList);
                evaluateRecycler.setLayoutManager(new GridLayoutManager(mContext, 5));
                evaluateRecycler.setAdapter(homeLoveAdapter);
            } else {
                // evaluateRecyclerLint.setVisibility(View.GONE);
            }

        }


    }

    @Override
    public void onLoadGaUserExtVoByIdFailed() {

    }

    @Override
    public void onLoadRelationSuccess(String s) {

    }

    @Override
    public void onLoadRelationFailed() {

    }

    @Override
    public void onLoadSelectByGsPresentPageListSuccess(GivePresentBean givePresentBean) {
        if (givePresentBean != null) {
            givePresentBeans.addAll(givePresentBean.getData().getList());
        }

    }

    @Override
    public void onLoadSelectByGsPresentPageListFailed() {

    }
}
